/*
 *  testjpeg.cpp
 *  Ray Tracing
 *
 *  Created by Jean-Marc Comby + Romain Dequesne on Mon May 17 2004.
 *  Copyright (c) 2004. All rights reserved.
 *
 */

#include "testjpeg.hpp"

void jpeg()
{
	unsigned int const hauteur(256);
	unsigned int const ratio(2);
	unsigned int const largeur(ratio*hauteur);
	
	ImageFileJpeg mon_image(largeur, hauteur,"essai.jpg", 90);
	
	Couleur const c1( 64,  64, 255);
	Couleur const c2( 64, 255,  64);
	
	for (unsigned int k(1); k < hauteur; k += 7 ) {
		
		Couleur c;
		if (k % 2) c = c1; else c = c2;
		
		unsigned int j0(ratio*k);
		
		for (unsigned int i(1); i < k; ++i) {
			unsigned int j( (largeur-j0) * i/k + j0 );
			mon_image.setPixel(        i,         j, c);
			mon_image.setPixel(hauteur-i, largeur-j, c);
		}
		for (unsigned int i(k); i <= hauteur; ++i) {
			unsigned int j( j0 * (i-k) / (hauteur-k) );
			mon_image.setPixel(        i,  largeur-j, c);
			mon_image.setPixel(hauteur-i,          j, c);
		}
		for (unsigned int j(1); j <= largeur; ++j) {
			unsigned int i( (largeur-j) * (hauteur-k)/j0 + k );
			mon_image.setPixel(        i,         j, c);
			mon_image.setPixel(hauteur-i, largeur-j, c);
		}
		for (unsigned int j(j0); j <= largeur; ++j) {
			unsigned int i( k * (j-j0) / (largeur-j0) );
			mon_image.setPixel(         i,         j, c);
			mon_image.setPixel( hauteur-i, largeur-j, c);
		}
	}
	
	mon_image.affiche();
}
